<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>二维码，取票码取票，退票页面</title>
<link rel="stylesheet" href="${ctx}/static/plug/weui/css/weui.css"
	media="all">

<link rel="stylesheet" href="${ctx}/static/plug/weui/css/weuix.css"
	media="all">
	<link rel="stylesheet" href="${ctx}/static/css/sellticket/checkCodePick.css"
	media="all">
<style type="text/css">
</style>



</head>
<body>
	<div class="header">
		<p>${modeType == 1 ? "取票" : "退票"}
		</p>
		<div class="datetime">
			<span class="times"></span> <span>${user.entNo}，你好</span>
		</div>
		<div class="tips">
			 <span>当前设备连接失败</span>
		</div>
	</div>
	<input type="hidden" value="${user.scenicSpotId}" id="scenicSpotId">
		<p align="center">请刷二维码，身份证或手动输入</p>
		<input type="hidden" value="${modeType}" id="modeType">
	<div class="subjects">
		<div id="ticket_purchase">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">取票码或身份证号</label></div>
        <div class="weui-cell__bd">
            <input class="weui-input" placeholder="请输入取票码（身份证）" type="number" oninput="if(value.length>18)value=value.slice(0,18)"  id="checkCode">
        </div>
    </div>
		
		</div>
	</div>
		<p align="center" id="manual">提交信息</p>
	
	<div class="tailer">
		<div class="returns">
			<p id = "returns">返回上一步</p>
		</div>
		
		<div class="returns">
				<p id="refund">退票</p>
			</div>
			
			<div class="returns">
				<p id="collection">取票</p>
			</div>
			
			<div class="returns">
				<p id="sell">售票</p>
			</div>
	</div>
	
</body>












<script src="${ctx}/static/js/jquery/jquery.min.js"></script>
<script src="${ctx}/static/js/jquery/aes.js"></script>
<script src="${ctx}/static/plug/weui/js/zepto.weui.js"
	type="text/javascript"></script>
<script src="${ctx}/static/plug/weui/js/zepto.min.js"
	type="text/javascript"></script>


<script>
	$(function() {
		
		$("#sell").click(function() {
			var scenicSpotId = $("#scenicSpotId").val();
			window.location.href="${ctx}/selling/toVoteTicket?scenicSpotId=" + scenicSpotId;
		});
		
		$("#collection").click(function() {
			window.location.href="${ctx}/takeOrRetreat/toCheckCodePick?modeType=" + 1;
		});
		$("#refund").click(function() {
			window.location.href="${ctx}/takeOrRetreat/toCheckCodePick?modeType="  + 2;
		});
		
		$("#returns").click(function() {
			window.location.href="${ctx}/selling/index";
		});
		
		$("#manual").click(function() {
			var codeVal = $("#checkCode").val();
			var modeType = $("#modeType").val();
			if(codeVal.length == 8 ){
				window.location.href="${ctx}/takeOrRetreat/checkCodePick?checkCode=" + codeVal + "&modeType=" + modeType;
				 return;
			}
			if(codeVal.length == 18 ){
				window.location.href="${ctx}/takeOrRetreat/idNumPick?idNumber=" + codeVal + "&modeType=" + modeType;
				 return;
			}
			$.toast("输入不正确", "forbidden");
		});
		webSocketConnect();
		function webSocketConnect() {
			if(localStorage.serverIP != null || localStorage.serverPort != null){
				var serverIP = localStorage.serverIP;
		   		var serverPort = localStorage.serverPort;
		   		var host = "ws://" + serverIP + ":" + serverPort + "/"
		        socket = new WebSocket(host);
		   	 	try {
	           	  socket.onopen = function (msg) {
	           		 $(".tips").css("display","none")
	            	};
	              socket.onmessage = function (msg) {
	                if (typeof msg.data == "string") {
	                		var data = $.parseJSON(msg.data);
	                		console.log(data)
	                		
							if(data.code == "001"){
								var deviceId = data.device_id;
								localStorage.deviceNo = deviceId;
	                			var resultStr =  data.data.qrcode;
	                			uuid = resultStr;
            					var params = {
            							"uuid" : uuid ,
            					}
            					$.post("${ctx}/takeOrRetreat/getCheckCode",params  , function(obj) {
            						if(obj.result){
            							$("#checkCode").val(obj.shortQrcode.checkCode);
            							return
            						}else{
            							$.alert("无效二维码！","提示",function(){});
            						}
            						
            					});	                			
	                		}
	                		
	                		if(data.code == "002"){
								var deviceId = data.device_id;
								var resultStr = data.data;
								console.log(resultStr);
								var name = resultStr.name;
								var idNumber = resultStr.cid;
								console.log(name + "   :   " + idNumber);
								$("#checkCode").val(idNumber);
	                		}
		                }
		                else {
		                    alert("非文本消息");
		                }
	            	};
	              socket.onclose = function (msg) { 
	            	  $.confirm("连接设备失败是否继续连接", "提示", function() {
	              		 webSocketConnect();
	                   }, function() {
	                       //取消操作
	                   });
	           		  };
	        	}catch (ex) {
		            log(ex);
		            webSocketConnect();
	        	}
			}else {
				$(".tips").css("display","block")
			}
		};
		
		
		
		
		getNowFormatDate();
		
		
		
	});
	
	function aesHexDecrypt(src) {
		var key = CryptoJS.enc.Utf8.parse("fb18fc197e644d38");
		console.log(src)
		console.log(CryptoJS.enc.Utf8.parse(src))
		var encryptedBase64Str = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse(src));
		console.log(encryptedBase64Str)
	    var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, {
	    	mode: CryptoJS.mode.ECB,
		    padding: CryptoJS.pad.Pkcs7
	    });
		console.log(decryptedData)
	    var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8);
		console.log(decryptedStr)
		return decryptedStr;
	}
	
	function getNowFormatDate() {
	    var date = new Date();
	    var seperator1 = "-";
	    var seperator2 = ":";
	    var month = date.getMonth() + 1;
	    var strDate = date.getDate();
	    var secondStr = date.getSeconds();
		var minuteStr = date.getMinutes();
		var hourStr = date.getHours();
	    if (month >= 1 && month <= 9) {
	        month = "0" + month;
	    }
	    if (strDate >= 0 && strDate <= 9) {
	        strDate = "0" + strDate;
	    }
	    if (secondStr >= 0 && secondStr <= 9) {
			secondStr = "0" + secondStr;
		}
		if (minuteStr >= 0 && minuteStr <= 9) {
			minuteStr = "0" + minuteStr;
		}
		if (hourStr >= 0 && hourStr <= 9) {
			hourStr = "0" + hourStr;
		}
		
		var currentdate = date.getFullYear() + seperator1 + month + seperator1
		+ strDate + " " + hourStr + seperator2 + minuteStr
		+ seperator2 + secondStr;
	    $(".times").text(currentdate);
	    setTimeout(getNowFormatDate, 1000);
	}
</script>


</html>